package Modele;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

public class Artefact extends Contenu {

	private String nom;
	private String image;
	private Bonus bonus;
	private int niveau;
	private int x;
	private int y;
	private static HashMap<String, Artefact> tabArtefacts = new HashMap<String, Artefact>();
	
	public Artefact(String n, String img, Bonus b, int niv) {
		this.image = img;
		this.nom = n;
		this.bonus = b;
		this.niveau = niv;
		this.x = 0;
		this.y = 0;
		Artefact.tabArtefacts.put(n, this);
	}
	
	public static void chargerArtefacts() {
		ResultSet resultat = null;
		String nom = "";
		int attaque = 0;
		int defense = 0;
		int pouvoir = 0;
		int intelligence = 0;
		int PVMonstres = 0;
		int resistanceMonstres = 0;
		int vitesseMonstres = 0;
		int contreAttaqueMonstres = 0;
		int niveau = 0;
		String chemin = "";
		Bonus b = null;
		try {
			resultat = Connexion.con.createStatement().executeQuery("SELECT * FROM Artefacts");
			while (resultat.next()) {
				nom = resultat.getString(1);
				chemin = resultat.getString(2);
				niveau = resultat.getInt(3);
				attaque = resultat.getInt(4);
				defense = resultat.getInt(5);
				pouvoir = resultat.getInt(6);
				intelligence = resultat.getInt(7);
				PVMonstres = resultat.getInt(8);
				vitesseMonstres = resultat.getInt(9);
				resistanceMonstres = resultat.getInt(10);
				contreAttaqueMonstres = resultat.getInt(11);
				b = new Bonus(attaque, defense, pouvoir, intelligence, PVMonstres, vitesseMonstres, resistanceMonstres, contreAttaqueMonstres);
				new Artefact(nom, chemin, b, niveau);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public int getX() {
		return this.x;
	}
	
	public int getY() {
		return this.y;
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public void setY(int y) {
		this.y = y;
	}
	
	public String getImage() {
		return this.image;
	}
	
	public int getNiveau() {
		return this.niveau;
	}
	
	public static HashMap<String, Artefact> getTabArtefacts() {
		return Artefact.tabArtefacts;
	}
	
	/*
	public static Artefact getArtefactByNiveau(int niv) {
		Artefact[] artefacts = new Artefact[8];
		int nbArtefact = 0;
		
		for(Entry<String, Artefact> entry : Artefact.tabArtefacts.entrySet()) {
		    if (entry.getValue().niveau == niv) {
		    	artefacts[nbArtefact] = entry.getValue();
		    	nbArtefact ++;
		    }
		}
		
		Random rand = new Random();
		Artefact a = artefacts[rand.nextInt(nbArtefact)];
		return a;
	}
	*/
	
	public String toString() {
		return "Nom : " + this.nom + "\n" + this.bonus.toString();
	}
	
}
